/**
 * 
 */
package com.homework.datastructures.exercise1.list;

/**
 * @author public_enemy
 * 
 */
public class ArrayList<E> {

	/**
	 * @param list
	 *            Generic Array
	 * @param counter
	 *            current number of elements
	 */
	Object[] list;
	private int counter;

	/**
	 * @param capacity
	 *            : maximum number of elements in the list
	 */
	public ArrayList(int capacity) {
		list = new Object[capacity];
		counter = 0;
	}

	/**
	 * @return current number of elements (counter)
	 */
	public int getNumberOfElements() {
		return counter;
	}

	/**
	 * 
	 * @param index
	 *            : element index
	 * @return value of the element on the specified index
	 */
	public Object getElementByIndex(int index) {
		return list[index];
	}

	/**
	 * The method add a specific value at the end of the list
	 * 
	 * @param value
	 *            : inserted value
	 * 
	 */
	public void addElement(E value) {
		if (counter < list.length) {
			list[counter] = value;
			counter++;
		} else {
			System.out.println("List limit exceed");
		}
	}

	/**
	 * Remove element from the end of the list
	 */
	public void removeElement() {
		list[counter] = null;
		counter--;
	}
}
